<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function request(options = { url: '', method: 'GET', body: null, success(data) { }, faield(reason) { } }) {
            const { url, method, body, success, faield } = options;
            const xhr = new XMLHttpRequest();
            xhr.open(method, url, true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        success(this.response);
                    }
                }
                else {
                    faield(this.statusText)
                }
            }
            xhr.send();
        }

        request({
            url: './data.json',
            method: 'GET',
            success(data) {
                console.log('data: ', data);
            },
            faield(reason) {
                console.log(reason);
            }
        });
    </script>
</body>

</html>